package com.xxl.job.admin.controller.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * web mvc config
 * 全局配置, 扩展Spring MVC的配置
 *
 * @author xuxueli 2018-04-02 20:48:20
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    private PermissionInterceptor permissionInterceptor;
    @Resource
    private CookieInterceptor cookieInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册自定义的拦截器, 注册多个拦截器时, 执行的先后顺序为注册的先后顺序

        // 权限拦截器, 进行权限校验, 查看用户是否登录, 查看用户是否为管理员, 拦截路径为全部请求
        registry.addInterceptor(permissionInterceptor).addPathPatterns("/**");

        // cookie拦截器, 进行cookie解析, 拦截路径为全部请求
        registry.addInterceptor(cookieInterceptor).addPathPatterns("/**");
    }

}